import { UserDto } from 'src/core/dto/user.dto';
import { UserService } from 'src/core/service/user.service';
import { Body, Controller, Get, Param, ParseIntPipe, Post, Put, UseFilters } from "@nestjs/common";
import { HttpExceptionFilter } from '../filter/HttpExceptionFilter';
import { ValidateMobilePipe } from '../pipe/ValidateMobilePipa';
import { ValidationPipe } from '../pipe/ValidationPipe';
@Controller('user')
@UseFilters(new HttpExceptionFilter)
export class UserController{
//注入service
constructor(private userService:UserService){}
@Get()
async searchUsers():Promise<UserDto[]> {
    return this.userService.searchUsers();//返回单个用户资源
}
@Get(':id')
async getUser(@Param('id',ParseIntPipe) id:number):Promise<UserDto>{
    //根据id拿用户信息返回用户
    return this.userService.getUser(id);
 }
 @Put(':id/modifyMobile')
 modifyMobile(
    @Param('id',ParseIntPipe) id:number,
    @Body('mobile',ValidateMobilePipe) mobile:string,
 ){
  return{
    id,
    mobile
  }  
 }
 @Post()
createUser(@Body(ValidationPipe) userDto: UserDto) {
  return userDto;
}
}